package jp.co.nes.awssupport.test.utility;

import java.util.ArrayList;
import java.util.List;

import jp.co.nes.awssupport.common.bean.ReservedManageBean;

/**
 * リザーブド管理アサーションヘルパーです。
 */
public class AssertReservedManageHelper extends AbstractAssertHelper<ReservedManageBean> {

    /** リザーブド管理の件数を検索する際に使用するSelect文 */
    private static final String SEL_COUNT = "select count(*) as Count from reserved_manage";

    /** リザーブド管理を検索する際のSelect文 */
    private static final String SEL = ""
            + "select ReservedInstanceId,"
            + "       SubscriptionId,"
            + "       PricingPlanId, "
            + "       LinkedAccountId,"
            + "       ProductName,"
            + "       RegionCode,"
            + "       MultiAz,"
            + "       ProductDescription,"
            + "       InstanceType,"
            + "       UsageStartDate,"
            + "       UsageEndDate,"
            + "       OfferingType,"
            + "       OfferingClass,"
            + "       Duration,"
            + "       Quantity,"
            + "       ReservationARN,"
            + "       YearMonth"
            + "  from reserved_manage"
            + " where ReservedInstanceId = ?";

    /**
     * デフォルトコンストラクタです。
     */
    public AssertReservedManageHelper() {
        super(ReservedManageBean.class);
    }

    /*
     * (非 Javadoc)
     * @see jp.co.nes.awssupport.test.utility.AbstractAssertHelper#getSelectCountQuery()
     */
    @Override
    protected String getSelectCountQuery() {
        return SEL_COUNT;
    }

    /*
     * (非 Javadoc)
     * @see jp.co.nes.awssupport.test.utility.AbstractAssertHelper#getSelectBeanQuery()
     */
    @Override
    protected String getSelectBeanQuery() {
        return SEL;
    }

    /*
     * (非 Javadoc)
     * @see jp.co.nes.awssupport.test.utility.AbstractAssertHelper#toConditionList(jp.co.nes.awssupport.common.bean.BaseBean)
     */
    @Override
    protected List<Object> toConditionList(ReservedManageBean bean) {
        List<Object> conditionList = new ArrayList<>();
        conditionList.add(bean.getReservedInstanceId());
        return conditionList;
    }

    /*
     * (非 Javadoc)
     * @see jp.co.nes.awssupport.test.utility.AbstractAssertHelper#isMatch(jp.co.nes.awssupport.common.bean.BaseBean, jp.co.nes.awssupport.common.bean.BaseBean)
     */
    @Override
    protected boolean isMatch(ReservedManageBean actualBean, ReservedManageBean expectedBean) {
        if (actualBean == null) {
            if (expectedBean == null) {
                return true;
            } else {
                return false;
            }
        } else {
            if (expectedBean == null) {
                return false;
            }
        }

        StringBuilder actual = new StringBuilder();
        actual.append(actualBean.getReservedInstanceId());

        StringBuilder expected = new StringBuilder();
        expected.append(expectedBean.getReservedInstanceId());

        if (actual.toString().equals(expected.toString())) {
            return true;
        }
        return false;
    }
}
